﻿package mortal.common
{
    import com.gengine.core.*;
    import com.gengine.core.call.*;
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import flash.text.*;
    import mortal.game.cache.*;

    public class ResManager extends Singleton
    {
        private var _caller:Caller;
        private var _isTitleLoaded:Boolean = false;
        private var _isBaseLoaded:Boolean = false;
        private var _isNumberLoaded:Boolean = false;
        private var _isSkillLoaded:Boolean = false;
        private var _isEnglishLoaded:Boolean = false;
        private static var _instance:ResManager;
        private static const TitleCall:String = "TitleCall";
        private static const NumberCall:String = "NumberCall";
        private static const EnglishCall:String = "EnglishCall";

        public function ResManager()
        {
            this._caller = new Caller();
            return;
        }// end function

        public function get isSkillLoaded() : Boolean
        {
            return this._isSkillLoaded;
        }// end function

        public function get isTitleLoaded() : Boolean
        {
            return this._isTitleLoaded;
        }// end function

        public function get isNumberLoaded() : Boolean
        {
            return this._isNumberLoaded;
        }// end function

        public function get isEnglishLoaded() : Boolean
        {
            return this._isEnglishLoaded;
        }// end function

        public function LoadFontBase() : void
        {
            if (this._isBaseLoaded == false)
            {
                this.LoadFont("FontBase.swf", "font.FontBase_base", this.loadBaseComplete);
            }
            return;
        }// end function

        private function loadBaseComplete() : void
        {
            this._isBaseLoaded = true;
            return;
        }// end function

        public function LoadFontNumber() : void
        {
            if (this._isNumberLoaded == false)
            {
                this.LoadFont("FontNumber.swf", "font.FontNumber_number", this.loadNumberComplete);
            }
            return;
        }// end function

        private function loadNumberComplete() : void
        {
            this._isNumberLoaded = true;
            this._caller.call(NumberCall);
            this._caller.removeCallByType(NumberCall);
            return;
        }// end function

        public function LoadFontTitle() : void
        {
            if (this._isTitleLoaded == false)
            {
                this.LoadFont("FontTitle.swf", "font.FontTitle_title", this.loadTitleComplete);
            }
            return;
        }// end function

        private function loadTitleComplete() : void
        {
            this._isTitleLoaded = true;
            this._caller.call(TitleCall);
            this._caller.removeCallByType(TitleCall);
            return;
        }// end function

        public function LoadFontSkill() : void
        {
            if (this._isSkillLoaded == false)
            {
                this.LoadFont("FontSkill.swf", "font.FontSkill_skill", this.loadSkillComplete);
            }
            return;
        }// end function

        private function loadSkillComplete() : void
        {
            this._isSkillLoaded = true;
            this._caller.call(NumberCall);
            this._caller.removeCallByType(NumberCall);
            return;
        }// end function

        public function LoadFontEnglish() : void
        {
            if (this._isEnglishLoaded == false)
            {
                this.LoadFont("FontEnglish.swf", "font.FontEnglish_englishFont1,font.FontEnglish_englishFont2", this.loadEnglishComplete, LoaderPriority.LevelA);
            }
            return;
        }// end function

        private function loadEnglishComplete() : void
        {
            this._isEnglishLoaded = true;
            this._caller.call(EnglishCall);
            this._caller.removeCallByType(EnglishCall);
            return;
        }// end function

        public function LoadFont(param1:String, param2:String, param3:Function = null, param4:int = 3) : void
        {
            var onLoadedHandler:Function;
            var swfName:* = param1;
            var className:* = param2;
            var completeCall:* = param3;
            var loaderPriority:* = param4;
            onLoadedHandler = function (param1:SWFInfo) : void
            {
                var _loc_3:Class = null;
                var _loc_2:* = className.split(",");
                for each (className in _loc_2)
                {
                    
                    _loc_3 = param1.getAssetClass(className);
                    if (_loc_3 != null)
                    {
                        Font.registerFont(_loc_3);
                    }
                }
                if (completeCall is Function)
                {
                    completeCall();
                }
                return;
            }// end function
            ;
            LoaderManager.instance.load(swfName, onLoadedHandler, loaderPriority, className);
            return;
        }// end function

        public function registerTitle(param1:Function) : void
        {
            if (this._isTitleLoaded == false)
            {
                this._caller.addCall(TitleCall, param1);
            }
            return;
        }// end function

        public function registerNumber(param1:Function) : void
        {
            if (this._isNumberLoaded == false)
            {
                this._caller.addCall(NumberCall, param1);
            }
            return;
        }// end function

        public function registerEnglish(param1:Function) : void
        {
            if (this._isEnglishLoaded == false)
            {
                this._caller.addCall(EnglishCall, param1);
            }
            return;
        }// end function

        public function loadFont() : void
        {
            this.LoadFontBase();
            this.LoadFontNumber();
            this.LoadFontTitle();
            return;
        }// end function

        public function loadLevelRes() : void
        {
            var _loc_1:* = Cache.instance.role.entityInfo.level;
            if (_loc_1 > 1)
            {
                this.LoadFontBase();
                this.LoadFontNumber();
            }
            if (_loc_1 > 9)
            {
                this.LoadFontTitle();
            }
            return;
        }// end function

        public static function get instance() : ResManager
        {
            if (_instance == null)
            {
                _instance = new ResManager;
            }
            return _instance;
        }// end function

    }
}
